﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Navigation;
using System.Threading;
using ClientLib.MonitorState2;
using ClientLib.Common;

using bus = WpfDataBingding.TaskServiceReference;
using WpfDataBingding.DevTreeData;

namespace WpfDataBingding
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            //设置用户名
            string userID = "user001";
            Application.Current.Properties["userID"] = userID;
                        
            bus.DataBusServiceClient dataBusServiceClient=null;
            try 
	        {	        
        		dataBusServiceClient=new bus.DataBusServiceClient();
                //初始化设备类型集合
                Application.Current.Properties["DeviceTypeArray"]=dataBusServiceClient.QueryAllDeviceTypeInfo();
                //初始化设备集合
                DataBus dataBus = new DataBus();
                dataBus.fillDataBusByRemoteService(dataBusServiceClient,userID);
                Application.Current.Properties["DataBus"] = dataBus;
	        }
	        catch (Exception e1)
	        {
        		MessageBox.Show(e1.Message);		        
	        }
            finally
            {
                if (dataBusServiceClient != null)
                    dataBusServiceClient.Close();
                dataBusServiceClient=null;
            }
            ////////////////////////////////////////////////////
            try
            {
                ThreadScan santhread = new ThreadScan();
                Application.Current.Properties["ScanDevice"] = santhread;
                new InitMonDevice(userID);
            }
            catch (Exception e1)
            {

                throw e1;
            }
        }

   
    }
    
}
